var Shengchanqiye = new Vue({
    el : "#Shengchanqiyelist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmu : {},
        shengchanqiye :{},
        shengchanqiyelist : [],
        show : false,					// 显示列表是否有数据


        shengchanqiye : {},
        id:'',

        pageIndex : 1,
        pageSize :500,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindShengchanqiyeList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        bindShengchanqiyeList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/shengchanqiye/findshengchanqiyelist",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                       "   <thead >\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">编号</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >药品品名</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >剂型</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">序号</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:80px;\" rowspan=\"2\" >药品名称</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:80px;\" rowspan=\"2\" >规格</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >单位</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >医保类别</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\"  >上级检查通报</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\"  >未挂网</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >无配送企业</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >原国谈</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >通过一致性评价</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:110px;\" >国家保密配方</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:110px;\" >中药保护品种</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >价格（元）</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >原研</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >基药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >集采</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >院本部</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">秦淮</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:110px;\" rowspan=\"2\">产品编码</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:80px;\" rowspan=\"2\" >生产企业</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">备注</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">品规类别</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\">操作</td>\n" +

                       "    </tr>\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:150px;\" colspan='3' >淘汰原则</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:320px;\" colspan='4'>绝对优先</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" colspan='2'>相对优先</td>\n" +
                       "    </tr></thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                   if(data.ShengchanList.length > 0){
                       _this.show = true;
                       _this.Shengchanqiyelist=data.ShengchanList;

                       var PageInfo = data.PageInfo;
                       _this.pageIndex = PageInfo.pageIndex;
                       _this.recordCount = PageInfo.recordCount;
                       _this.pageCount = PageInfo.pageCount;

                       for (var i = 0; i < data.ShengchanList.length; i++) {
                           var mmShengchan = data.ShengchanList[i];

                           var mmPinzhongbinahao=mmShengchan.pinzhongbianhao;
                           var mmYaopinpingming=mmShengchan.yaopinpinming;
                           var mmJixing=mmShengchan.jixing;


                           var mmPinguiList = mmShengchan.pinguilist;
                           var mmPinzhongHebingshu = mmShengchan.pinzhonghebinghang;

                           for (var j = 0; j < mmPinguiList.length; j++) {
                               var s=0;

                               var mmPinguilist = mmPinguiList[j];

                               var mmPinguixuhao = parseInt(mmPinguilist.pinguixuhao);
                               var mmYaopinmingcheng = mmPinguilist.yaopinmingcheng;
                               var mmGuige = mmPinguilist.guige;
                               var mmDanwei = mmPinguilist.danwei;
                               var mmYibaoleibie = mmPinguilist.yibaoleibie;
                               var mmPinguileibie=mmPinguilist.pinguileibie;

                               var mmShengchanqiyeList= mmPinguilist.shengchanqiyelist;
                               var mmPinguiHebingshu = mmPinguilist.pinguihebinghang;

                               for (var k = 0; k < mmShengchanqiyeList.length; k++) {
                                   var mmlist = mmShengchanqiyeList[k];
                                   var mmId=mmlist.id;
                                   var mmJianchatongbao = mmlist.jianchatongbao;
                                   var mmWeiguawang = mmlist.weiguawang;
                                   var mmWupeisongqiyehu = mmlist.wupeisongqiye;
                                   var mmYuanguotan = mmlist.yuanguotan;
                                   var mmYizhixingpingjia= mmlist.yizhixingpingjia;
                                   var mmBaomipeifang=mmlist.baomipeifang;
                                   var mmBaohupinzhong=mmlist.baohupinzhong;
                                   var mmJiage = mmlist.jiage;
                                   var mmYuanyan = mmlist.yuanyan;
                                   var mmJiyao = mmlist.jiyao;
                                   var mmJicai = mmlist.jicai;
                                   var mmYuanbenbu = mmlist.yuanbenbu;
                                   var mmQinhuai = mmlist.qinhuai;
                                   var mmChanpinbianma= mmlist.chanpinbianma;
                                   var mmShengchanqiye = mmlist.shengchanqiye;
                                   var mmBeizhu = mmlist.beizhu;

                                   var mmHuanhangfu = "";
                                   var mmerjihe="";
                                   var mmyijihe="";
                                   var mmsanjihe="";
                                   if (k != 0) {
                                       mmHuanhangfu = "<tr>";
                                   }else{
                                       mmerjihe = "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinguiHebingshu + "'>" + mmPinguixuhao + "</td>";
                                       mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 80px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmYaopinmingcheng + "</td>";
                                       mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 80px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'  rowspan='" + mmPinguiHebingshu + "'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                       mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmDanwei + "</td>";
                                       mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmYibaoleibie + "</td>";
                                       mmsanjihe = "<td style='text-align:center;vertical-align:middle;width: 50px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmPinguileibie + "</td>";
                                   }
                                   if(j==0 &&s==0){
                                       mmyijihe= "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongbinahao + "</td>";
                                       mmyijihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmYaopinpingming + "</td>";
                                       mmyijihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmJixing + "</td>";
                                       s= 1;
                                   }

                                   mmHtml +=mmyijihe;
                                   mmHtml +=mmerjihe;

                                   var mmBtn="<span class=\"btn btn-primary\" style=\"\"\n" +
                                       "                  onclick=\"toModify('"+mmPinguixuhao+"','"+mmYaopinmingcheng+"','"+mmGuige+"','"+mmlist.id+"')\">修改</span>";


                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jianchatongbao' style=\"text-align:center;\">" + mmJianchatongbao + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_weiguawang' style=\"text-align:center;\">" + mmWeiguawang + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_wupeisongqiye' style=\"text-align:center;\">" + mmWupeisongqiyehu + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yuanguotan' style=\"text-align:center;\">" + mmYuanguotan + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yizhixingpingjia' style=\"text-align:center;\">" + mmYizhixingpingjia + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width:110px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden;'><a id='a_"+mmId+"_baomipeifang' title='" + mmBaomipeifang + "'><div id='div_"+mmId+"_baomipeifang' style=\"text-align:center;text-overflow: ellipsis; overflow: hidden;\">" + mmBaomipeifang + "</div></a></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width:110px;'><div id='div_"+mmId+"_baohupinzhong' style=\"text-align:center;\">" + mmBaohupinzhong + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jiage' style=\"text-align:center;\">" + mmJiage + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_yuanyan' style=\"text-align:center;\">" + mmYuanyan + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jiyao' style=\"text-align:center;\">" + mmJiyao + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'><div id='div_"+mmId+"_jicai' style=\"text-align:center;\">" + mmJicai + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmYuanbenbu + "</td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmQinhuai + "</td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 110px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a id='a_"+mmId+"_chanpinbianma' title='" + mmChanpinbianma + "'><div id='div_"+mmId+"_chanpinbianma' style=\"text-align:center;text-overflow: ellipsis; overflow: hidden;\">" + mmChanpinbianma + "</div></a></td>";
                                   // mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmChanpinbianma + "</td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width: 80px;'><div id='div_"+mmId+"_shengchanqiye' style=\"text-align:center;\">" + mmShengchanqiye + "</div></td>";
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmBeizhu + "</td>";
                                   mmHtml +=mmsanjihe;
                                   mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBtn + "</td>";
                                   mmHtml += "</tr>";

                               }
                           }

                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</tbody></table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        bindShengchanqiye:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/shengchanqiye/find_one', {
                id : _this.id,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.shengchanqiye = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        modifyShengchanqiye:function (){
            var _this = this;
            layer.open({type:3});
            var jianchatongbao=$.trim(_this.shengchanqiye.jianchatongbao);
            var weiguawang=$.trim(_this.shengchanqiye.weiguawang);
            var wupeisongqiye=$.trim(_this.shengchanqiye.wupeisongqiye);
            var yuanguotan=$.trim(_this.shengchanqiye.yuanguotan);
            var yizhixingpingjia=$.trim(_this.shengchanqiye.yizhixingpingjia);
            var baomipeifang=$.trim(_this.shengchanqiye.baomipeifang);
            var baohupinzhong=$.trim(_this.shengchanqiye.baohupinzhong);
            var jiage=$.trim(_this.shengchanqiye.jiage);
            var yuanyan=$.trim(_this.shengchanqiye.yuanyan);
            var jiyao=$.trim(_this.shengchanqiye.jiyao);
            var jicai=$.trim(_this.shengchanqiye.jicai);
            var chanpinbianma=$.trim(_this.shengchanqiye.chanpinbianma);
            var shengchanqiye=$.trim(_this.shengchanqiye.shengchanqiye);

            $("#div_"+_this.id+"_jianchatongbao").html(jianchatongbao);
            $("#div_"+_this.id+"_weiguawang").html(weiguawang);
            $("#div_"+_this.id+"_wupeisongqiye").html(wupeisongqiye);
            $("#div_"+_this.id+"_yuanguotan").html(yuanguotan);
            $("#div_"+_this.id+"_yizhixingpingjia").html(yizhixingpingjia);
            $("#div_"+_this.id+"_baomipeifang").html(baomipeifang);
            $("#div_"+_this.id+"_baohupinzhong").html(baohupinzhong);
            $("#div_"+_this.id+"_jiage").html(jiage);
            $("#div_"+_this.id+"_yuanyan").html(yuanyan);
            $("#div_"+_this.id+"_jiyao").html(jiyao);
            $("#div_"+_this.id+"_jicai").html(jicai);
            $("#div_"+_this.id+"_chanpinbianma").html(chanpinbianma);
            $("#div_"+_this.id+"_shengchanqiye").html(shengchanqiye);
            $("#a_"+_this.id+"_baomipeifang").prop('title',baomipeifang);
            $("#a_"+_this.id+"_chanpinbianma").prop('title',chanpinbianma);

            $.post('/shengchanqiye/modify',{
                id : _this.id,
                jianchatongbao:jianchatongbao,
                weiguawang:weiguawang,
                wupeisongqiye:wupeisongqiye,
                yuanguotan:yuanguotan,
                yizhixingpingjia:yizhixingpingjia,
                baomipeifang:baomipeifang,
                baohupinzhong:baohupinzhong,
                jiage:jiage,
                yuanyan:yuanyan,
                jiyao:jiyao,
                jicai:jicai,
                chanpinbianma:chanpinbianma,
                shengchanqiye:shengchanqiye,
                random : Math.random()
            },function(ppData){
                if(ppData != null){
                    layer.closeAll("loading");

                    if(ppData.result == "1"){
                        layer.open({
                            time:1000,
                            btn:[],
                            content:"保存成功!",
                        });
                        $("#editShengchanqiyeModal").modal("hide");
                        // _this.bindXiangmuList();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        toRandomsmpling:function (){
            var _this = this;

            layer.confirm("确定抽取吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/shengchanqiye/randomsmpling", {
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"抽取成功!",
                            });
                            _this.bindShengchanqiyeList();
                        }
                    }
                },"json");
            })
        },


        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindShengchanqiyeList();
        }
    }
});
